package com.sofwin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sofwin.mapper.SysDeptMapper;
import com.sofwin.pojo.SysDept;
import com.sofwin.pojo.SysDeptExample;
import com.sofwin.service.DeptService;

import java.util.List;

/**
 * ClassName: DeptServiceImpl
 * Description: TODO
 * date: 2022/4/16 10:58 上午
 *
 * @author andyliu
 * @qq 115176513
 * @since JDK 1.8
 */
public class DeptServiceImpl implements DeptService {
    private SysDeptMapper mapper;
    public boolean saveOrUpdateDept(SysDept dept) {
        boolean status = false;
        if(dept.getId()!=null){
            status = mapper.updateByPrimaryKeySelective(dept)==1?true:false;
            return status;
        }
        status = mapper.insertSelective(dept)==1?true:false;
        return status;
    }

    public SysDept queryById(Integer deptId) {
        return mapper.selectByPrimaryKey(deptId);
    }

    public PageInfo<SysDept> queryDepts(SysDept dept, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        SysDeptExample deptExample = new SysDeptExample();
        SysDeptExample.Criteria criteria = deptExample.createCriteria();
        if(dept!=null){
            if(dept.getDeptName()!=null && !"".equals(dept.getDeptName())){
                criteria.andDeptNameLike("%"+dept.getDeptName()+"%");
            }
        }
        List<SysDept> depts = mapper.selectByExample(deptExample);
        return new PageInfo<SysDept>(depts);
    }

    public List<SysDept> queryDetps(SysDept dept) {
        SysDeptExample deptExample = new SysDeptExample();
        SysDeptExample.Criteria criteria = deptExample.createCriteria();
        if(dept!=null){
            if(dept.getDeptName()!=null && !"".equals(dept.getDeptName())){
                criteria.andDeptNameLike("%"+dept.getDeptName()+"%");
            }
        }
        List<SysDept> depts = mapper.selectByExample(deptExample);
        return  depts;
    }

    public boolean removeById(Integer id) {
        return mapper.deleteByPrimaryKey(id)==1?true:false;
    }

    public void setMapper(SysDeptMapper mapper) {
        this.mapper = mapper;
    }
}
